$('.login a').on('click',function() {
    $('.register').show();
});
$('.register a').on('click',function() {
    $('.register').hide();
})
$('.login form').on('submit',function(e) {
    e.preventDefault();
    let data = $(this).serialize();
    axios.post('/api/login',data).then(res => {
        // console.log(res)
        if(res.data.status === 0) {
            localStorage.setItem('token',res.data.token);
            layer.msg(res.data.message,() => {
                location.href = './index.html'
            })
        }
    })
})
$('.register form').on('submit',function(e) {
    e.preventDefault();
    let data = $(this).serialize();
    axios.post('/api/reguser',data).then(res => {
        // console.log(res)
        let {status,message} = res.data;
        if (status === 0) {
            layer.msg(message);
            $('.register form')[0].reset();
            $('.register').hide();
        }
    })
})
let form = layui.form;
form.verify({
    len: [
        /^[\S]{6,12}$/
        ,'密码必须6到12位，且不能出现空格'
      ] ,
    same: function(val){
        let pwd = $('.pwd').val();
        if (pwd !== val) {
            return '两次密码不一致'
        }
    }
})